<!-- 
 * Tournament bracket system for use in scenarios 
 * like sports, computer gaming or other games.
 * 
 * @link http://www.toggymedy.com
 * @license  GNU/GPL, ( http://www.gnu.org/licenses/gpl.txt )
 * @authors Team Excellence

 * The tournament bracket is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * Last update: 2009-11-27
 -->

<?php
	include_once('../dbconnect.php');
	$turnid = $_POST['turnid'];
	$query = mysql_query("select * from paamelding
	inner join lag on paamelding.lagid = lag.lagid
	inner join turnering on paamelding.turnid = turnering.turnid
	where turnering.turnid = $turnid 
	order by paamelding.regid");
	$kamp = mysql_query("select * from kamp where kamp.turnid = $turnid order by kamp.kampid");
	$query2 = mysql_query("select lag.lagid from paamelding
	inner join lag on paamelding.lagid = lag.lagid
	where paamelding.turnid = $turnid 
	order by paamelding.regid limit 4,4");
	

	if(isset($_POST['turnid']))
	{
		mysql_query("UPDATE turnering SET startet = 1 where turnering.turnid = $turnid");
		Print "<b>Turneringen med id $turnid ble startet</b>";
	}
	$t = 0;
	while ($info = mysql_fetch_array( $query ))
	{
		if($t < 4)
		{ 
			mysql_query("insert into kamp (turnid, laga) values ($turnid, $info[lagid])");
		}
		else if ($t > 4 && $t < 8)
		{
			while($info2 = mysql_fetch_array($kamp))
			{
				mysql_query("update kamp (lagb) values ($info[lagid]) where kamp.kampid = $info2[kampid]");
			}			
		}
		$t++;		
	}
/*	while ($info2 = mysql_fetch_array( $query2 ))		
	{
		$lagb = mysql_fetch_array( $kamp )
		mysql_query("update kamp set lagb = $info2[lagid] where kamp.kampid = $lagb[kampid]");
	}

	echo "Done lizam";
*/
?>
